// UVa11020 Efficient Solutions
// 刘汝佳
#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
  bool operator<(const Point& p2) const {
    if (x != p2.x) return x < p2.x;
    return y < p2.y;
  }
};
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int T;
  cin >> T;
  for (int n, t = 1; t <= T; t++) {
    cin >> n;
    if (t > 1) puts("");
    printf("Case #%d:\n", t);
    multiset<Point> s;
    Point p;
    for (int i = 0; i < n; i++) {
      cin >> p.x >> p.y;
      auto it = s.lower_bound(p);
      if (it == s.begin() || prev(it)->y > p.y)
        for (s.insert(p), it = s.upper_bound(p); it != s.end() && it->y >= p.y;)
          s.erase(it++);
      printf("%lu\n", s.size());
    }
  }
  return 0;
}
// 24489044 11020 Efficient Solutions Accepted  C++11 0.020 2020-01-31